/*
 * 各中医馆门诊基础信息统计js
 * @author 杨腊梅
 * 2016/1/20
 * 
 */
$('#tcm_businessTotal_eCharts').css('height',orange.detailPage.getHeight());
$('#tcm_businessTotal_eCharts').css('width',orange.detailPage.getWidth());
$('#total_yearDate').val(new Date().Format('yyyy'));
$('#tcm_businessTotal_grid').datagrid(
		{
			url:"d/total/table",
			queryParams:{
				orgGuid:$("#tcmcpdetail_guid").val(),
				year:$("#total_yearDate").val()
			},
			singleSelect:true,
			rownumbers:true,
			columns:[[
			          {field:'orgName',title:'月份',width:'23%',sortable:true,halign:'center'},
			          {field:'outAtol',title:"门诊次数",width:'25%',sortable:true,halign:'center'},
				      {field:'inAtol',title:"出院人次",width:'25%',sortable:true,halign:'center'},
				      {field:'outTcmp',title:"门诊中药房总量",width:'25%',sortable:true,halign:'center'},
			          ]],
			pagination:true,
			sortable:true,
			sortName:'tcm_name',
			sortOrder:'asc'
		}
);

/**
 * 查询业务总量
 */
function businessTotal_query(){
	$('#tcm_businessTotal_grid').datagrid({
		url:"d/total/table",
		queryParams:{
			orgGuid:$("#tcmcpdetail_guid").val(),
			year:$("#total_yearDate").val()
		}
	})
	initBusinessTotalCharData();
}
var tcm_myChart = echarts.init($('#tcm_businessTotal_eCharts')[0]);
var tcm_initData;
var tcm_clinic_sum = [];
var tcm_out_hospital_sum = [];
var tcm_xAxisData = [];
initBusinessTotalCharData();
function initBusinessTotalCharData(){
	tcm_clinic_sum.length = 0;
	tcm_out_hospital_sum.length = 0;
	tcm_xAxisData.length = 0;
	$.ajax({
		url:"d/total/chart",
		type:"get",
		data:{orgGuid:$("#tcmcpdetail_guid").val(),
			year:$("#total_yearDate").val()},
		success:function(data){
			debugger;
			tcm_initData = JSON.parse(data);
			tcm_initData = tcm_initData.chart1;
			for(var i=0; i<tcm_initData.length; i++) {
				tcm_clinic_sum.push(tcm_initData[i].outAtol);
				tcm_out_hospital_sum.push(tcm_initData[i].inAtol);
				tcm_xAxisData.push(tcm_initData[i].period);
			}
			tcm_myChart.setOption(tcm_option);
		}
	});

}
/*
 * 设置图表格式
 */
tcm_option={
		grid:{
			show:false,
			bottom :'15%',
			top:'25%',
			height:'65%',
			width:'80%',
			left:'10%',
			right:'15%'
		},
		
		tooltip : {
			trigger : 'axis'
		},
		
		legend : {
			top : '5%',
			data : ['门诊次数', '出院人次']
		},
		
		xAxis : [{
			type : 'category',
			boundaryGap : false,
			data : tcm_xAxisData
		}],
		
		yAxis : [{
			type:'value'
		}],
		
		series : [
		  {
			  type : 'line',
			  name : "门诊次数",
			  smooth : true,
			  data : tcm_clinic_sum
		  },
		  {
			  type : 'line',
			  name : "出院人次",
			  smooth : true,
			  data : tcm_out_hospital_sum
		  }
		],
};

//使用刚指定的配置项和数据显示图表
tcm_myChart.setOption(tcm_option);